package com.origon360.Services;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.origon.entities.Category;
import com.origon.entities.Country;
import com.origon.entities.Currency;
import com.origon.entities.Deal;
import com.origon.entities.Shop;

@Stateless
public  class CommonService {
	
	@PersistenceContext
	EntityManager em;

	public Country findCountryByName(String value){		
		Country country = (Country) em.createQuery("FROM Country where name =:countryName")
				.setParameter("countryName", value).getSingleResult();				
		return country;
	}
	
	public Category findCategoryByName(String value){
		Category category = (Category)em.createQuery("FROM Category WHERE type =:categoryName", Category.class)
				.setParameter("categoryName", value).getSingleResult();
		return category;		
	
	}
	
	public Currency findCurrencyByName(String value){
		Currency currency = (Currency)em.createQuery("FROM Currency WHERE name =:currencyName", Currency.class)
					.setParameter("currencyName", value).getSingleResult();
			return currency;
	}
	
	public Deal findDealByName(String value){
		Deal deal = (Deal)em.createQuery("FROM Deal WHERE DealType =:DealType", Deal.class)
					.setParameter("DealType", value).getSingleResult();
			return deal;
	}
	
	public Shop findShopByName(String value){
		Shop shop = (Shop)em.createQuery("FROM Shop WHERE name =:shopName", Shop.class)
					.setParameter("shopName", value).getSingleResult();
			return shop;
	}
}
